<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<head>
    <meta charset="UTF-8">
    <title>编辑课程 - 企业培训平台</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
    <style>
        /* 可以为表单添加一些简单的样式 */
        .form-container {
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            max-width: 800px;
            margin: 20px auto;
        }

        .form-group {
            margin-bottom: 1rem;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: bold;
            color: #495057;
        }

        .form-group input[type="text"],
        .form-group input[type="number"],
        .form-group textarea,
        .form-group select { /* 添加 select 的样式 */
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .form-group input[type="file"] { /* 文件输入框的样式 */
            border: none;
            padding: 0;
            margin-top: 5px; /* 添加一些上边距 */
        }

        .form-group textarea {
            resize: vertical;
            min-height: 100px;
        }
        .form-actions {
            text-align: right;
            margin-top: 20px;
        }
        .form-actions button, .form-actions a {
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            text-decoration: none; /* For the anchor tag as a button */
            display: inline-block; /* For the anchor tag as a button */
            margin-left: 10px; /* Space between buttons */
        }
        .btn-primary {
            background-color: #007bff;
            color: white;
        }
        .btn-secondary {
            background-color: #6c757d;
            color: white;
        }

        /* 针对当前封面图片的样式 */
        .current-image-preview {
            margin-bottom: 15px;
            border: 1px dashed #ccc; /* 虚线框，更明显 */
            padding: 10px;
            border-radius: 4px;
            text-align: center; /* 图片居中 */
        }
        .current-image-preview p {
            margin-top: 0;
            margin-bottom: 8px;
            font-weight: bold;
        }
        .current-image-preview img {
            max-width: 150px; /* 限制图片大小 */
            height: auto;
            border: 1px solid #eee; /* 添加边框 */
            border-radius: 4px;
            display: block; /* 使图片独占一行并居中 */
            margin: 0 auto;
        }
        .text-muted {
            font-size: 0.85em;
            color: #6c757d;
            margin-top: 5px;
            display: block; /* 确保小字信息独占一行 */
        }
    </style>
</head>
<body>
<div th:replace="~{fragments/header :: header}"></div>
<div class="main-container">
    <div th:replace="~{fragments/sidebar :: sidebar}"></div>
    <div class="content">
        <h2>编辑课程</h2>
        <div class="form-container">
            <form th:action="@{/course/edit}" th:object="${course}" method="post" enctype="multipart/form-data">
                <input type="hidden" th:field="*{id}">
                <div class="form-group">
                    <label for="couName">课程名称:</label>
                    <input type="text" id="couName" th:field="*{couName}" required>
                </div>
                <div class="form-group">
                    <label for="typeId">课程类型:</label>
                    <select id="typeId" th:field="*{typeId}" required>
                        <option value="">请选择课程类型</option>
                        <option value="1" th:selected="${course.typeId == 1}">编程语言</option>
                        <option value="2" th:selected="${course.typeId == 2}">数据分析</option>
                        <option value="3" th:selected="${course.typeId == 3}">设计</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="couInfo">课程介绍:</label>
                    <textarea id="couInfo" th:field="*{couInfo}" rows="5"></textarea>
                </div>
                <div class="form-group">
                    <label for="couPrice">价格:</label>
                    <input type="number" id="couPrice" th:field="*{couPrice}" step="0.01" min="0">
                </div>

                <div class="current-image-preview">
                    <p>当前封面图片:</p>
                    <img th:src="${course.couPic}" alt="当前封面图片">
                </div>

                <div class="form-group">
                    <label for="couPicFile">上传新封面图片:</label>
                    <input type="file" id="couPicFile" name="couPicFile" accept="image/*">
                    <small class="text-muted">选择新图片将替换当前封面。</small>
                </div>

                <div class="form-actions">
                    <button type="submit" class="btn btn-primary">更新课程</button>
                    <a th:href="@{/course/manage}" class="btn btn-secondary">取消</a>
                </div>
            </form>
        </div>
    </div>
</div>
<div th:replace="~{fragments/footer :: footer}"></div>
</body>
</html>